package com.jtlrm.ckd.mvp.model;

import com.base.sdk.base.model.BaseModel;
import com.base.sdk.base.net.LifeCycleEvent;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.jtlrm.ckd.net.RetrofitUtil;

import java.io.File;

import io.reactivex.Observer;
import io.reactivex.subjects.PublishSubject;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

public class ResourceModel extends BaseModel {

    public void uploadImage(File file, Observer observer, PublishSubject<LifeCycleEvent> lifecycleSubject) {
        MultipartBody.Part body =
                MultipartBody.Part
                        .createFormData("file", file.getName(), RequestBody.create(MultipartBody.FORM, file));
        MultipartBody.Part dir =
                MultipartBody.Part
                        .createFormData("dir", "header");
        RetrofitUtil.composeToSubscribe(RetrofitUtil.getFileService().uploadImage(dir, body), observer, lifecycleSubject);
    }

    public void getCode(String Key, Observer observer, PublishSubject<LifeCycleEvent> lifecycleSubject) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("Key", Key);
        RetrofitUtil.composeToSubscribe(RetrofitUtil.getService().queryCode(jsonObject), observer, lifecycleSubject);
    }

    public void queryApkVersion(Observer observer, PublishSubject<LifeCycleEvent> lifecycleSubject) {
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("clientType", 3);
        jsonObject.addProperty("platformType", 1);
        RetrofitUtil.composeToSubscribe(RetrofitUtil.getService().queryAppVersion(jsonObject), observer, lifecycleSubject);
    }


    public interface KeyCode{
        String WEN_HUAN_CHENGDU = "whcd";
        String BAO_XIAO_FANG_SHI = "bxfs";
        String YUAN_FA_BING = "yfb";
        String BAN_SUI_JI_BING = "bsjb";
    }
}
